package com.itfreer.data.input.entity;

import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Transient;

import com.itfreer.form.api.entity.EntityBase;
import com.itfreer.form.api.reflect.DictionaryField;

/**
 * 数据导入配置
 */
@Entity(name = "data_input_config")
public class InputConfigEntity extends EntityBase implements Serializable {

	private static final long serialVersionUID = -4660135056281381403L;

	/**
	 * 导入配置编号
	 */
	@Id
	@Column(name = "id")
	private String id;

	/**
	 * 导入配置名称
	 */
	@Column(name = "s_name", length = 50, nullable = false)
	private String name;

	/**
	 * 导入检查类型 如果不指定，则使用默认的检查项
	 */
	@Column(name = "s_checktype", length = 50, nullable = true)
	@DictionaryField(dictionaryName = "d_check_type", toFieldName = "typeName")
	private String checkType;

	@Transient
	private String checkTypeName;

	/**
	 * 数据重复策略
	 */
	@DictionaryField(dictionaryName = "d_repetition_strategy", toFieldName = "repetitionStrategyName")
	@Column(name = "s_repetition_strategy", length = 50, nullable = true)
	private String repetitionStrategy;

	/**
	 * 数据重复策略
	 */
	@Transient
	private String repetitionStrategyName;

	/**
	 * 详细配置信息
	 */
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	@JoinColumn(name = "s_mid")
	@OrderBy("i_order ASC")
	private Set<InputConfigItemEntity> items = new LinkedHashSet<>();

	public InputConfigEntity() {

	}

	public InputConfigEntity(String id, String name) {
		this.id = id;
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCheckType() {
		return checkType;
	}

	public void setCheckType(String checkType) {
		this.checkType = checkType;
	}

	@Transient
	public String getCheckTypeName() {
		return checkTypeName;
	}

	public void setCheckTypeName(String checkTypeName) {
		this.checkTypeName = checkTypeName;
	}

	public String getRepetitionStrategy() {
		return repetitionStrategy;
	}

	public void setRepetitionStrategy(String repetitionStrategy) {
		this.repetitionStrategy = repetitionStrategy;
	}

	@Transient
	public String getRepetitionStrategyName() {
		return repetitionStrategyName;
	}

	public void setRepetitionStrategyName(String repetitionStrategyName) {
		this.repetitionStrategyName = repetitionStrategyName;
	}

	public Set<InputConfigItemEntity> getItems() {
		return items;
	}

	public void setItems(Set<InputConfigItemEntity> items) {
		this.items = items;
	}
}
